package com.groupname.dangerousdelves;

// -------------------------------------------------------------------------
/**
 *  Write a one-sentence summary of your class here.
 *  Follow it with additional details about its purpose, what abstraction
 *  it represents, and how to use it.
 *
 *  @author Chris Fieldman
 *  @version 2012.11.19
 */
public class CircularBuffer
{
    //~-------------------------------------------------------------------------
    // Member Variables
    private int[] buffer;
    private int capacity;
    private int position;
    private int size;

    //~-------------------------------------------------------------------------
    // Constructors
    /**
     * Create a new CircularBuffer object.
     * @param size
     */
    public CircularBuffer(int size)
    {
        this.buffer = new int[size];
        this.capacity = size;
        this.position = 0;
        this.size = 0;
    }

    //~-------------------------------------------------------------------------
    // Methods
    public void enqueue(int value)
    {
        this.buffer[size] = value;
        this.size++;
    }

    public int next()
    {
        int next = this.buffer[position];

        this.position = this.position++ % this.capacity;

        return next;
    }
}
